﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
using IPTV.DBUtility;
using IPTV.module;
using System.Data;

/// <summary>
/// Summary description for PlateDao
/// </summary>
namespace IPTV.dao
{
    public class GradeDao
    {
        public GradeDao()
        {
            
        }

        public string getId(string name)
        {

            string sql = " select g.id from grade g where g.name = @name ";

            MySqlParameter[] parms = new MySqlParameter[] 
                { 
                    new MySqlParameter( "@name" , MySqlDbType.VarChar, 36 )
                };

            parms[0].Value = name;
            string id = null;
            try
            {
                MySqlDataReader reader = MySQLHelper.ExecuteReader(MySQLHelper.CONNECTION_STRING, sql, parms);

                while (reader.Read())
                {
                    id = reader[0].ToString();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return id;

        }


        public List<itv_zhzt_list> getZtById(string id)
        {

            string sql = " select id , sourceid, url, displayorder ,title from itv_zhzt_list where zhztinfoid = @id ORDER BY displayorder asc ";

            MySqlParameter[] parms = new MySqlParameter[] 
                { 
                    new MySqlParameter( "@id" , MySqlDbType.VarChar, 36 )
                };

            parms[0].Value = id;
            List<itv_zhzt_list> ztList = new List<itv_zhzt_list>();
            try
            {
                MySqlDataReader reader = MySQLHelper.ExecuteReader(MySQLHelper.CONNECTION_STRING, sql, parms);

                while (reader.Read())
                {
                    itv_zhzt_list zt = new itv_zhzt_list();
                    zt.Id = reader[0].ToString();
                    zt.Sourceid = reader[1].ToString();
                    zt.Url = reader[2].ToString();
                    zt.Displayorder = reader[3].ToString();
                    zt.Title = reader[4].ToString();
                    ztList.Add(zt);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return ztList;

        }
    
    }
}